"use strict";
var __extends = (this && this.__extends) || function (d, b) {
    for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
    function __() { this.constructor = d; }
    d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
var BaseController_1 = require('./BaseController');
var AddGroupDto_1 = require('../dtos/groups/AddGroupDto');
var UpdateGroupDto_1 = require('../dtos/groups/UpdateGroupDto');
var GroupsService_1 = require('../services/GroupsService');
var GroupController = (function (_super) {
    __extends(GroupController, _super);
    function GroupController(app) {
        _super.call(this, app);
        var $this = this;
        app.post(this.domain + "/groups", function (req, res) {
            $this.handerErr(req, res, function () {
                $this.addGroup(req, res);
            }, true);
        });
        app.put(this.domain + "/groups/:id", function (req, res) {
            $this.handerErr(req, res, function () {
                $this.updateGroup(req, res);
            }, true);
        });
        app.get(this.domain + "/groups/:id", function (req, res) {
            $this.handerErr(req, res, function () {
                $this.getGroup(req, res);
            }, true);
        });
        app.get(this.domain + "/groups/project/:id", function (req, res) {
            $this.handerErr(req, res, function () {
                $this.getGroups(req, res);
            }, true);
        });
        app.delete(this.domain + "/groups/:id", function (req, res) {
            $this.handerErr(req, res, function () {
                $this.deleteGroup(req, res);
            }, true);
        });
        this.groupsService = new GroupsService_1.GroupsService();
    }
    GroupController.prototype.addGroup = function (req, res) {
        this.groupsService.addGroup(AddGroupDto_1.AddGroupDto.toGroup(req.body), function (err, group) {
            res.send(JSON.stringify(group));
        });
    };
    GroupController.prototype.updateGroup = function (req, res) {
        var id = req.params.id;
        console.log(JSON.stringify(UpdateGroupDto_1.UpdateGroupDto.toGroup(id, req.body)));
        this.groupsService.updateGroup(UpdateGroupDto_1.UpdateGroupDto.toGroup(id, req.body), function (err, group) {
            console.log(JSON.stringify(group));
            res.send(JSON.stringify(group));
        });
    };
    GroupController.prototype.getGroup = function (req, res) {
        var groupId = req.params.id;
        this.groupsService.getGroup(groupId, function (err, group) {
            res.send(JSON.stringify(group));
        });
    };
    GroupController.prototype.getGroups = function (req, res) {
        var projectId = req.params.id;
        this.groupsService.getGroups(projectId, function (err, groups) {
            res.send(JSON.stringify(groups));
        });
    };
    GroupController.prototype.deleteGroup = function (req, res) {
        var groupId = req.params.id;
        this.groupsService.deleteGroup(groupId, function (err, group) {
            res.send(JSON.stringify(group));
        });
    };
    return GroupController;
}(BaseController_1.BaseController));
exports.GroupController = GroupController;
